package com.eastedu.converter;

import com.eastedu.client.encrypt.model.FileEncryptRequest;
import com.eastedu.client.file.model.FileInfoResponse;
import com.eastedu.repository.basic.po.BasicResourceFilePO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;

import java.util.List;

/**
 * The interface Basic resource file converter.
 *
 * @author zhangzhishuai
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface BasicResourceFileConverter {
    /**
     * Update.
     *
     * @param fileInfoResponse the file info response
     * @param po               the po
     */
    @Mapping(target = "previewUrl", source = "urls.preview")
    @Mapping(target = "downloadUrl", source = "urls.download")
    @Mapping(target = "fileId", source = "id")
    @Mapping(target = "encryption", ignore = true)
    @Mapping(target = "duration", ignore = true)
    @Mapping(target = "basicResourceId", ignore = true)
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    void update(FileInfoResponse fileInfoResponse, @MappingTarget BasicResourceFilePO po);



    /**
     * To FileEncryptRequest
     *
     * @param baseResourceId baseResourceId
     * @param fileIds        fileIds
     * @return FileEncryptRequest
     */
    @Mapping(target = "appCode", constant = "resource-center-basic-file-service")
    @Mapping(target = "content", source = "baseResourceId")
    FileEncryptRequest toFileEncryptRequest(String baseResourceId, List<Long> fileIds);
}
